<?php
//专题前台
if(!defined('IN_T')){
	die('hacking attempt');
}

$tid = intval($_REQUEST['t']);

if($tid>0){
	$sql = "select * from ".$Base->table('topic_cat')." where id=$tid";
	$t = $Db->query($sql,'Row');
}

//列表页
if(empty($t)){
	
	//提取专题列表
	$page = intval($_REQUEST['page']);
	$page = $page<1 ? 1: $page;
	$sql= "select * from ".$Base->table('topic_cat')." order by id desc";
	$res = $Db->query($sql);
	foreach($res as $k=>$v){	
		//提取第一个作品的封面
		$sql = "select pname,img_path from ".$Base->table('topic')." where tid=".$v['id']." order by id desc limit 6";
		$res[$k]['works'] = $Db->query($sql);
	}
	//print_r($res);
	$tp->assign('res',$res);
	$tp->assign('title','专题');
	
}
else{
	$sql = "SELECT t.*,w.view_uuid,w.cdn_host FROM ".$Base->table('topic')." as t ".
		   "LEFT JOIN ".$Base->table('worksmain')." as w ON w.pk_works_main=t.pid ".
		   "WHERE t.tid = ".$t['id']." ".
		   "ORDER BY t.sort_order ASC";
	
	$t['list'] = $Db->query($sql);
	//print_r($t);
	$tp->assign("t",$t);
	$tp->assign('title',$t['name']);
	$tp->assign('description',$t['brief']);
}
$tp->display($_lang['moban'].'/topic.tpl');
exit;
?>